import java.util.Arrays;

public class Test2 {
    //leetcode 峰与谷
    //https://leetcode.cn/problems/peaks-and-valleys-lcci/description/?envType=problem-list-v2&envId=greedy
    public void wiggleSort(int[] nums) {
        int[] sorted = nums.clone();
        Arrays.sort(sorted);
        int n = nums.length;

        int left = (n - 1) / 2;
        int right = n - 1;

        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                nums[i] = sorted[left--];
            } else {
                nums[i] = sorted[right--];
            }
        }
    }
}
